package com.siwei.mes.entity.excel;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.entity.experiment.CheckBatchConfig;
import com.siwei.mes.entity.system.TestProjectInfo;
import com.siwei.mes.enums.GenerateCodeEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * 导入批检指标配置实体
 *
 * @Description: 导入批检指标配置实体
 * @Version: 1.0
 * @author: mlchen
 * @date: 2025/7/15 15:23
 */
@Data
@Accessors(chain = true)
public class ImportCheckBatchConfigExcel {
    @Excel(name = "物料类型", replace = {"水泥_1", "粉煤灰_2", "矿渣粉_3", "粗骨料_4", "细骨料_5", "外加剂_6", "混凝土_7"}, addressList = true, width = 15)
    private String projectCategory = "";

    @Excel(name = "试验项目名称", width = 15)
    private String testProjectName = "";

    @Excel(name = "检测类型", replace = {"常规_0", "月检_10", "季检_20", "半年检_30", "年检_40"}, addressList = true, width = 15)
    private String checkType = "";

    @Excel(name = "检测值单位", width = 15)
    private String checkValueUnit = "";

    @Excel(name = "国标值", width = 15)
    private String nationalStandardValue = "";

    @Excel(name = "试验依据", width = 15)
    private String experimentGist = "";

    @Excel(name = "判断依据", width = 15)
    private String judgeGist = "";

    @Excel(name = "检测方法", width = 15)
    private String checkMethod = "";

    @Excel(name = "设备编号，多选用英文分号拼接", width = 50)
    private String equipmentNo = "";

    @Excel(name = "上传检验图片", replace = {"是_1", "否_0"}, addressList = true, width = 15)
    private String isUploadImg = "";

    @Excel(name = "是否必检", replace = {"是_1", "否_0"}, addressList = true, width = 15)
    private String isMust = "";

    /**
     * 组装批检指标配置
     *
     * @param batchConfigExcel 导入的批检指标配置
     * @param testProjectInfo  试验项目配置信息
     * @return
     */
    public static CheckBatchConfig payloadCheckBatchConfigInfo(ImportCheckBatchConfigExcel batchConfigExcel, TestProjectInfo testProjectInfo) {
        CheckBatchConfig checkBatchConfig = new CheckBatchConfig();
        checkBatchConfig.setId(null);
        checkBatchConfig.setBatchCode(UidUtils.genNo(GenerateCodeEnum.CHECK_BATCH.getCode()));
        checkBatchConfig.setProjectCategory(Integer.valueOf(batchConfigExcel.getProjectCategory()));
        checkBatchConfig.setNationalStandardValue(batchConfigExcel.getNationalStandardValue());
        checkBatchConfig.setTestProjectCode(testProjectInfo.getTestCode());
        checkBatchConfig.setTestProjectName(testProjectInfo.getTestName());
        checkBatchConfig.setCheckValueUnit(batchConfigExcel.getCheckValueUnit());

        try {
            if (batchConfigExcel.getIsUploadImg() != null) {
                checkBatchConfig.setIsUploadImg(Integer.valueOf(batchConfigExcel.getIsUploadImg()));
            } else {
                checkBatchConfig.setIsUploadImg(0);
            }
        } catch (Exception e) {
            checkBatchConfig.setIsUploadImg(0);
        }

        try {
            if (batchConfigExcel.getIsMust() != null) {
                checkBatchConfig.setIsMust(Integer.valueOf(batchConfigExcel.getIsMust()));
            } else {
                checkBatchConfig.setIsMust(0);
            }
        } catch (Exception e) {
            checkBatchConfig.setIsMust(0);
        }
        checkBatchConfig.setCreateTime(new Date());
        checkBatchConfig.setUpdateTime(new Date());
        checkBatchConfig.setIsDel(0);
        checkBatchConfig.setExperimentGist(batchConfigExcel.getExperimentGist());
        checkBatchConfig.setJudgeGist(batchConfigExcel.getJudgeGist());
        checkBatchConfig.setCheckMethod(batchConfigExcel.getCheckMethod());
        checkBatchConfig.setEquipmentNo(batchConfigExcel.getEquipmentNo());
        checkBatchConfig.setCheckType(Integer.valueOf(batchConfigExcel.getCheckType()));
        return checkBatchConfig;
    }
}
